const express=require('express')
const router=express.Router()

const multer=require('multer')
const storage=multer.diskStorage({
    destination:function(req,file,cb){
        cb(null,'public/images')
    },
    filename:function(req,file,cb){
        let newfileName=new Date().getTime()+""+file.originalname
        cb(null,newfileName)
    }
})
const upload=multer({storage})

// 编写文件上传的路由
router.post('/profile',upload.single('avatar'),(req,res,next)=>{
    console.log(req.file.filename);
    res.send({
        code:1,
        message:'图像上传成功',
        avatarPath:req.file.filename
    })
})

module.exports=router